<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>检索文档 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/_retrieving_a_document.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/_retrieving_a_document.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/_retrieving_a_document.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/_retrieving_a_document.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="getting-started.html">基础入门</a></span>
»
<span class="breadcrumb-link"><a href="intro.html">你知道的, 为了搜索…​</a></span>
»
<span class="breadcrumb-node">检索文档</span>
</div>
<div class="navheader">
<span class="prev">
<a href="_indexing_employee_documents.html">« 索引员工文档</a>
</span>
<span class="next">
<a href="_search_lite.html">轻量搜索 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="_retrieving_a_document"></a>检索文档<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/010_Intro/30_Tutorial_Search.asciidoc">edit</a>
</h2>
</div></div></div>
<p>目前我们已经在 Elasticsearch 中存储了一些数据，接下来就能专注于实现应用的业务需求了。第一个需求是可以检索到单个雇员的数据。</p>
<p>这在 Elasticsearch 中很简单。简单地执行 一个 HTTP <code class="literal">GET</code> 请求并指定文档的<em>地址</em> - 索引、类型和ID。使用这三个信息可以返回原始的 JSON 文档：</p>
<div class="pre_wrapper lang-sense">
<pre class="programlisting prettyprint lang-sense">GET /megacorp/employee/1</pre>
</div>
<div class="sense_widget" data-snippet="snippets/010_Intro/30_Get.json"></div>
<p>返回结果包含了文档的一些 元数据(metadata)，以及 <code class="literal">_source</code> 字段，内容是雇员 John Smith 的原始 JSON 文档：</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "_index" :   "megacorp",
  "_type" :    "employee",
  "_id" :      "1",
  "_version" : 1,
  "found" :    true,
  "_source" :  {
      "first_name" :  "John",
      "last_name" :   "Smith",
      "age" :         25,
      "about" :       "I love to go rock climbing",
      "interests":  [ "sports", "music" ]
  }
}</pre>
</div>
<div class="tip admon">
<div class="icon"></div>
<div class="admon_content">
<p>将 HTTP 命令由 <code class="literal">PUT</code> 改为 <code class="literal">GET</code> 可以用来检索文档，同样的，可以使用动词 <code class="literal">DELETE</code> 来删除文档，以及使用动词 <code class="literal">HEAD</code> 来检查文档是否存在。要用更新后的版本替换现有的文档，只需再次 <code class="literal">PUT</code> 。</p>
</div>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="_indexing_employee_documents.html">« 索引员工文档</a>
</span>
<span class="next">
<a href="_search_lite.html">轻量搜索 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>